package com.sjf.day02.Queue;

import java.util.Scanner;

/**
 * @author <huangtang>
 * @since 2021/12/16 11:00
 **/
public class CircleArrayDemo {

    public static void main(String[] args) {
        CircleQueue queue = new CircleQueue(4); //队列有效数个数为3
        char key = ' ';
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;

        while (loop) {
            System.out.print("s(show):显示队列\t\t");
            System.out.print("e(exit):退出程序\t\t");
            System.out.print("a(add):添加数据到队列\t\t");
            System.out.print("g(get):从队列取出数据\t\t");
            System.out.println("h(head):查看队列头的数据\t\t");
            key = scanner.next().charAt(0); // 接收一个字符
            switch (key) {
                case 's':
                    queue.showQueue();
                    break;
                case 'e':
                    scanner.close();
                    loop = false;
                    break;
                case 'a':
                    System.out.println("输出一个数:");
                    int value = scanner.nextInt();
                    queue.addQueue(value);
                    break;
                case 'g':
                    int a = 0;
                    try {
                        a = queue.getQueue();
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    System.out.println("取出的数是：" + a);
                case 'h':
                    int i = 0;
                    try {
                        i = queue.headQueue();
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    System.out.println("队列头的数是：" + i);
                default:
                    break;
            }
        }
    }
}
